package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import liumengbaio.lolzhangyoubao.Activity.View.CustomDialogLocationSelect;
import liumengbaio.lolzhangyoubao.R;

public class AddShowPlayActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView iconhero;
    private TextView tv_hero_nicker_name, tv_game_location;
    private Bundle bundle;
    private SharedPreferences sp;
    private ImageView btn_Summoner_spells_one,btn_Summoner_spells_two;
    private SharedPreferences.Editor editor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_show_play);
        sp = getSharedPreferences("summonerSkill", MODE_PRIVATE);
        editor=sp.edit();
        initView();
        initData();
    }

    private void initData() {
        Picasso.with(AddShowPlayActivity.this).load(bundle.getString("pic_url")).into(iconhero);
        tv_hero_nicker_name.setText(bundle.getString("nicker_name"));
        tv_game_location.setOnClickListener(this);
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        if(sp.getString("flag","").equals("2")==true) {
            Picasso.with(AddShowPlayActivity.this).load(sp.getString("pic_url1","")).into(btn_Summoner_spells_one);
            Picasso.with(AddShowPlayActivity.this).load(sp.getString("pic_url2","")).into(btn_Summoner_spells_two);
        }
    }

    private void initView() {
        bundle = getIntent().getExtras();
        findViewById(R.id.edit_head_left_title).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editor.putString("flag","0");
                finish();
            }
        });
        findViewById(R.id.relative_summoner_spells).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent_relative_summoner_spells=new Intent(AddShowPlayActivity.this,SummonerSkillActivity.class);
                startActivity(intent_relative_summoner_spells);
            }
        });
        findViewById(R.id.relative_add_skills).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent_relative_add_skills=new Intent(AddShowPlayActivity.this,AddSkillsActivity.class);
                intent_relative_add_skills.putExtras(bundle);
                startActivity(intent_relative_add_skills);
            }
        });
        iconhero = (ImageView) findViewById(R.id.iconhero);
        tv_hero_nicker_name = (TextView) findViewById(R.id.tv_hero_nicker_name);
        tv_game_location = (TextView) findViewById(R.id.tv_game_location);
        btn_Summoner_spells_one= (ImageView) findViewById(R.id.btn_Summoner_spells_one);
        btn_Summoner_spells_two= (ImageView) findViewById(R.id.btn_Summoner_spells_two);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_game_location:
                setDoBlack_voice();
                break;
        }
    }
    private void setDoBlack_voice() {
        final CustomDialogLocationSelect.Builder builder_signal_balck_voice = new CustomDialogLocationSelect.Builder(this);
        builder_signal_balck_voice.setTitle("地图选择:");
        builder_signal_balck_voice.setMessage("极地大乱斗-嚎哭深渊");
        builder_signal_balck_voice.setPositiveButton("关闭", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

            }
        });

        builder_signal_balck_voice.setNegativeButton("关闭",
                new android.content.DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        tv_game_location.setText(builder_signal_balck_voice.getMessage());
                        dialog.dismiss();
                    }
                });

        builder_signal_balck_voice.create().show();
    }
}
